#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=400, maxm=4000;
const long long inf=0x7fffffffffff;

long long min(long long a, long long b) {
  return a<b ? a : b;
}

class Graph {
public:
  int n, m, ind[maxn+1], to[2*maxm+2], link[2*maxm+2], gap[maxn+1], las[maxn+1];
  long long val[2*maxm+2], a[maxn+1], dis[maxn+1];
  bool flag;

  void init(int n) {
    this->n = n;
    m = 1;
    gap[0]=n;
    for (int i=1; i<=n; i++) {
      dis[i] = ind[i] = 0;
    }
    flag = false;
  }

  void addSide(int u, int v, int w) {
    m++;
    to[m] = v;
    val[m] = w;
    link[m] = ind[u];
    las[u] = ind[u] = m;
  }

  long long runFlow(int s, int t, long long have) {
    if (s==t) {
      return have;
    }
    long long run=0;
    for (int i=las[s]; i; i=link[i]) {
      if (dis[to[i]]+1==dis[s] && val[i]) {
	las[s] = i;
	int temp=runFlow(to[i], t, min(have-run, val[i]));
	run += temp, val[i]-=temp, val[i^1]+=temp;
	if (run==temp || flag) {
	  return run;
	}
      }
    }
    if (!(gap[dis[s]]--)) {
      flag = true;
    }
    gap[++dis[s]]++;
    las[s]=ind[s];
    return run;
  }

  void spfa(int s) {
    static int que[maxn+1];
    static bool book[maxn+1];
    for (int i=1; i<=n; i++) {
      book[i]=false, dis[i]=inf;
    } 
    dis[s]=0, que[1]=s, book[s]=true;
    for (int h=0, t=1; h!=t; ) {
      h = h%n+1;
      book[que[h]] = false;
      for (int i=ind[que[h]]; i; i=link[i]) {
	if (dis[to[i]]>dis[que[h]]+val[i]) {
	  dis[to[i]] = dis[que[h]]+val[i];
	  if (!book[to[i]]) {
	    book[to[i]] = true;
	    t = t%n+1;
	    que[t] = to[i];
	  }
	}
      }
    }
  }

  bool isOnly(int s, int t, long long have) {
    long long sum=0;
    static int que[maxn+1], book[maxn+1];
    for (int i=1; i<=n; i++) {
      book[i]=0;
    }
    que[1]=s, book[s]=1;
    for (int h=0, t=1; h!=t; ) {
      h++;
      for (int i=ind[que[h]]; i; i=link[i]) {
	if (i%2==0 && val[i] && !book[to[i]]) {
	  book[to[i]] = 1;
	  que[++t] = to[i];
	}
      }
    }
    que[1]=t, book[t]=2;
    for (int h=0, t=1; h!=t; ) {
      h++;
      for (int i=ind[que[h]]; i; i=link[i]) {
	if (i%2!=0 && val[i^1] && !book[to[i]]) {
	  book[to[i]]=2;
	  que[++t] = to[i];
	}
      }
    }
    for (int i=1; i<=n; i++) {
      for (int j=ind[i]; j; j=link[j]) {
	if (j%2==0 && book[i]==1 && book[to[j]]==2) {
	  sum += val[j^1];
	  if (a[i]==a[to[j]]) {
	    return false;
	  }
	}
      }
    }
    return sum==have;
  }
};

int main() {
#ifdef DEBUG
  freopen("3348.in", "r", stdin);
  freopen("3348.out", "w", stdout);
#endif

  static Graph g, net;
  int t;
  scanf("%d", &t);
  for (int ti=1; ti<=t; ti++) {
    int n, m;
    scanf("%d %d", &n, &m);
    g.init(n), net.init(n);
    for (int i=1; i<n; i++) {
      scanf("%lld", &g.a[i]);
      net.a[i] = g.a[i];
    }
    net.a[n] = g.a[n] = inf;
    for (int i=1; i<=m; i++) {
      int u, v;
      long long c;
      scanf("%d %d %lld", &u, &v, &c);
      g.addSide(u, v, c);
      g.addSide(v, u, c);
    }

    g.spfa(1);

    for (int i=1; i<=n; i++) {
      for (int j=g.ind[i]; j; j=g.link[j]) {
	if (g.dis[g.to[j]]==g.dis[i]+g.val[j]) {
	  net.addSide(i, g.to[j], min(g.a[i], g.a[g.to[j]]));
	  net.addSide(g.to[j], i, 0);
	}
      }
    }
    
    long long ans=0;
    for (; !net.flag; ans+=net.runFlow(1, n, inf));

    printf(net.isOnly(1, n, ans) ? "Yes %lld\n" : "No %lld\n", ans);
  }

  fclose(stdin);
  fclose(stdout);
  return 0;
}
